<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <title>文章管理</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  <script type="text/javascript" charset="utf-8" src="plug-in/Formdesign/js/ueditor/ueditor.config.js"></script>
  <script type="text/javascript" charset="utf-8" src="plug-in/Formdesign/js/ueditor/ueditor.all.min.js"> </script>
  <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
  <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
  <script type="text/javascript" charset="utf-8" src="plug-in/Formdesign/js/ueditor/lang/zh-cn/zh-cn.js"></script>
	 <script type="text/javascript">
		 $(function() {
			 mallArticleModule.init();
		 });
		 var mallArticleModule = (function(){
			 //初始化树
			 var initArticleCategoryTree = function () {
				 $('#articlecategoryid_').combotree({
					 url : 'mallArticleCategoryController.do?categorytree&selfId=${mallArticlePage.id}',
					 panelHeight: 200,
					 width: 157,
					 onClick: function(node){
						 var ismulty = $(node.attributes).prop("ismulty");
						 if(ismulty == 0){//不允许多篇文章
							 isHave(node.id);
						 }
						 $("#articlecategoryid").val(node.id);
					 }
				 });
			 }
			 //初始化UE
			 var initUE = function(){
				 UE.getEditor('editor');
			 }
			 //托管ue的图片上传
			 var trustUEimageUpload = function(){
				 UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
				 UE.Editor.prototype.getActionUrl = function(action){
					 if(action == 'uploadimage'){
						 var str = getRootPath() + "/ueditorUploadController.do?imageup";
						 return str;
					 }else{
						 return this._bkGetActionUrl.call(this, action);
					 }
				 }
			 }
			 //获取项目名称
			 var getRootPath = function(){
				 //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
				 var curWwwPath=window.document.location.href;
				 //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
				 var pathName=window.document.location.pathname;
				 var pos=curWwwPath.indexOf(pathName);
				 //获取主机地址，如： http://localhost:8083
				 var localhostPath=curWwwPath.substring(0,pos);
				 //获取带"/"的项目名，如：/uimcardprj
				 var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
				 return(localhostPath+projectName);
			 }
			 //设置不能编辑
			 var isHave = function(categoryId){
				 $.ajax({
					 async: false,
					 type: "post",
					 dataType:"json",
					 url: getRootPath() + "/mallArticleController/ishave/"+categoryId+".do",
					 success: function (data) {
						 if(!data.handleState){
							 alert(data.message);
							 //遗留问题
							 var id = $("#id").val();
							 if(id != null && id != "" && typeof (id) != "undefined"){//编辑
								alert("不能选择该分类，该分类只允许有一遍文章，并且文章已存在！");
							 }
						 }
					 },
					 error: function (error) {
						 console.log(error);
					 }
				 });
			 }

			 var module = {
				 init :function(){
					 initArticleCategoryTree();
					 initUE();
					 trustUEimageUpload();
				 },
			 }
			 return module;
		 })();
	 </script>
 </head>
 <body style="overflow-y: hidden" scroll="no">
  <t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="table" action="mallArticleController.do?save">
			<input id="id" name="id" type="hidden" value="${mallArticlePage.id }">
			<table style="width: 600px;" cellpadding="0" cellspacing="1" class="formtable">
				<tr>
					<td align="right">
						<label class="Validform_label">
							文章标题:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="articletitle" name="articletitle"
							   value="${mallArticlePage.articletitle}">
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							文章分类:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="articlecategoryid_"  value="${mallArticlePage.mallArticleCategoryEntity.categoryname}">
						<input class="inputxt" id="articlecategoryid" type="hidden"  datatype="*" name="articlecategoryid" value="${mallArticlePage.articlecategoryid}">
						<span class="Validform_checktip"></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							排序:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="sort" name="sort" value="${mallArticlePage.sort}" datatype="n">
						<span class="Validform_checktip"></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							是否置顶:
						</label>
					</td>
					<td class="value">
						<select id="istop" name="istop" datatype="*">
							<option value="1" <c:if test="${mallArticlePage.istop eq 1}">selected </c:if>>是</option>
							<option value="0" <c:if test="${mallArticlePage.istop eq 0}">selected </c:if> >否</option>
						</select>
						<span class="Validform_checktip"></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							文章内容:
						</label>
					</td>
				</tr>
				<tr>
					<td></td>
					<td colspan="4">
						<div>
							<script id="editor" name="articlecontent" datatype="*" type="text/plain"  style="width:800px;height:500px;">${mallArticlePage.articlecontent}</script>
						</div>
					</td>
				</tr>

			</table>
		</t:formvalid>
 </body>